package com.dg.cuckoo.admin.service.impl;

import com.dg.cuckoo.admin.dto.basicInformation.label.OneLabelDto;
import com.dg.cuckoo.admin.dto.basicInformation.label.TwoLabelDto;
import com.dg.cuckoo.admin.dto.basicInformation.projectInformation.TheLabelDto;
import com.dg.cuckoo.admin.repository.OneLabelRepository;
import com.dg.cuckoo.admin.repository.TheLabelRepository;
import com.dg.cuckoo.admin.repository.TwoLableRepository;
import com.dg.cuckoo.admin.service.TwoLabelService;
import com.dg.cuckoo.admin.service.WarrantLabelService;
import com.dg.cuckoo.admin.vo.FreeVo;
import com.dg.cuckoo.common.utils.PageModel;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class WarrantLabelServiceimpl implements WarrantLabelService {

    @Autowired
    private OneLabelRepository oneLabelRepository;
    @Autowired
    private TheLabelRepository theLabelRepository;
    @Autowired
    private TwoLabelService twoLabelService;

    @Override
    public String select() {
        List<OneLabelDto> oneLabelDtos = oneLabelRepository.findAll();
        List<FreeVo> freeVos = twoLabelService.selectView();
        JSONObject json = new JSONObject();
        json.put("onelabel",oneLabelDtos);//一级标签
        json.put("freeVos",freeVos);//树和数据
        return json.toString();
    }

    @Override
    public PageModel page(Integer page, Integer pageSize) {
        Integer one = page;
        page = (page - 1) * pageSize;
        int size = oneLabelRepository.findAll().size();
        List<OneLabelDto> list = oneLabelRepository.page(page, pageSize);
        PageModel model = new PageModel(one, pageSize, size, list);
        return model;
    }

    @Override
    public List<String> openInfo(String id) {
        List<TheLabelDto> dtos = theLabelRepository.findByByMark(id);
        List<String> list=new ArrayList<>();
        for(TheLabelDto t:dtos){
            list.add(t.getLable());
        }
        return list;
    }

}
